home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Graphics Plus
/
Graphics Plus.iso
/
general
/
visulztn
/
sphinx
/
sphinx.lha
/
utils
/
print_cm.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-27
|
1KB
|
74 lines
#include <stdio.h>
#include <fcntl.h>
/*
Print a Sphinx Color-map
*/
struct color_map
{
short red [256];
short green [256];
short blue [256];
};
typedef struct color_map color_map;
main(argc,argv)
int argc;
char * argv [];
{
int fd_in;
color_map red_map, green_map, blue_map;
if (argc != 2)
{
fprintf(stderr,"Usage is %s color-map-file\n",argv[0]);
exit(1);
}
fd_in = open(argv[1],O_RDONLY);
if (fd_in < 0)
{
fprintf(stderr,"Cannot read %s\n",argv[1]);
exit(1);
}
read_map(fd_in,&blue_map, "blue");
read_map(fd_in,&green_map,"green");
read_map(fd_in,&red_map, "red");
print_map(&red_map, 'r');
print_map(&green_map,'g');
print_map(&blue_map, 'b');
exit(0);
}
read_map(fd_in,map,name)
int fd_in;
color_map * map;
char * name;
{
int n;
n = read(fd_in,map->red,sizeof(map->red));
if (n != (sizeof(map->red))) return(-1);
n = read(fd_in,map->green,sizeof(map->green));
if (n != (sizeof(map->green))) return(-1);
n = read(fd_in,map->blue,sizeof(map->blue));
if (n != (sizeof(map->blue))) return(-1);
return(0);
}
print_map(map,bank)
color_map * map;
char bank;
{
int i;
for (i = 0; i < 256; i++)
{
printf("%c %03d %03d %03d %03d\n",
bank,i,map->red[i],map->green[i],map->blue[i]);
}
}